package binaryTree;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import utils.binaryTreeUtil.TreeNode;

public class rightSideView {
    List<Integer> list =new ArrayList<>();
    HashMap<Integer,Integer> map =new HashMap();
    
    public List<Integer> rightSideView(TreeNode root) {
        if (root==null) {
            return list;
        }else if(root.left==null&&root.right==null){
            list.add(root.val);
            return list;
        }
        preOreder(0, root);
        int length=map.size();
        for(int i=0;i<length;i++){
            list.add(map.get(i));
        }
        return list;
    }
    //前序or中序都可以
    public void preOreder(int depth,TreeNode root){
        if(root==null){
            return;
        }
        map.put(depth, root.val);
        preOreder(depth+1, root.left);
        preOreder(depth+1, root.right);

    }
    public static void main(String[] args) {
        
    }
}
